#ifndef xpack_graphic_draw_polyline
#define xpack_graphic_draw_polyline
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::graphic_draw_polyline::inc
#include"define/base_type.hpp"
#include"graphic/draw/line.hpp"
#include"macro/xexport.hpp"
#include"math/point.hpp"
#include"interface/unified_seq.hpp"
#pragma pop_macro("xuser")

namespace mixc::graphic_draw_polyline::inc{
    template<class seq_t, class rander_t>
    inline void polyline_core(inc::pt2wx start, seq_t const & point_list, rander_t const & rander){
        if (point_list->length <= uxx(1)){
            return;
        }

        for(uxx i = 0, length = point_list->length; i + 1 < length; i++){
            auto begin          = point_list[i](start->x, start->y);
            auto end            = point_list[i + 1](start->x, start->y);
            inc::draw::line(begin, end, rander);
        }
    }
}

namespace mixc::graphic_draw_polyline::origin{
    template<class seq_t, class rander_t>
    requires(inc::can_unified_seqlizex<seq_t, inc::pt2wx>)
    inline void polyline(inc::pt2wx start, seq_t && point_list, rander_t const & rander){
        inc::unified_seq<seq_t> list(point_list);
        inc::polyline_core(start, list, rander);
    }

    template<class seq_t, class rander_t>
    requires(inc::can_unified_seqlizex<seq_t, inc::pt2wx>)
    inline void polyline(seq_t && point_list, rander_t const & rander){
        inc::unified_seq<seq_t> list(point_list);
        inc::polyline_core({}, list, rander);
    }
}

#endif

xexport_spacex(draw, mixc::graphic_draw_polyline::origin)
